/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Services;

import Entities.Artist;
import Entities.Song;
import Entities.Soundtrack;
import java.util.Date;
import javax.persistence.*;
import java.util.List;

/**
 *
 * @author Edwin
 */
public class SongService {

    protected EntityManager em;

    public SongService(EntityManager em) {
        this.em = em;
    }

    public Song createSong(Long id,String title,Float duration,
            Artist artistEntity,Soundtrack soundtrackEntity) {
        Song song = new Song(id);
        song.setTitle(title);
        song.setDuration(duration);
        song.setArtistEntity(artistEntity);
        song.setSoundtrackEntity(soundtrackEntity);
       
                
        em.persist(song);
        
        return song;
    }
    
    
    public void updateSong(Long id,String title,Float duration,
            Artist artistEntity,Soundtrack soundtrackEntity) {
        Song song = findSong(id);
        song.setTitle(title);
        song.setDuration(duration);
        song.setArtistEntity(artistEntity);
        song.setSoundtrackEntity(soundtrackEntity);
        
        em.persist(song);
    }  
        
    public void removeSong(Long ID) {
        Song song = findSong(ID);
        if (song != null) {
            em.remove(song);
        }
    }

    public Song findSong(Long ID) {
        return em.find(Song.class, ID);
    }

    
}
